package 力扣日常刷题.木22一月.第13天0121;

/**
 * @author 帅小伙
 * @date 2022/1/21
 * @description
 */
public class Demo47动态规划预测赢家{




    public boolean PredictTheWinner(int[] nums) {
        int length = nums.length;
        int[][] dp = new int[length][length];
        for (int i = 0; i < length; i++) {
            dp[i][i] = nums[i];
        }

        for (int i = length - 2; i >= 0 ; i--) {
            for (int j = i+1; j < length ; j++) {
                dp[i][j] = Math.max(nums[i] - dp[i+1][j] , nums[j] - dp[i][j-1]);
            }
        }
        return dp[0][length-1] >= 0;
    }


}
